package com.car.mapper;

import com.car.pojo.MaintenanceAppointment;
import com.car.pojo.MaintenanceAppointmentQueryParam;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 保养预约Mapper接口
 */
@Mapper
public interface MaintenanceAppointmentMapper {
    
    /**
     * 分页查询保养预约
     */
    List<MaintenanceAppointment> page(@Param("param") MaintenanceAppointmentQueryParam param);
    
    /**
     * 查询总记录数
     */
    Long count(@Param("param") MaintenanceAppointmentQueryParam param);
    
    /**
     * 根据ID查询保养预约详情
     */
    MaintenanceAppointment getById(@Param("id") Long id);
    
    /**
     * 更新预约状态和分配保养员
     */
    void updateStatus(@Param("id") Long id, @Param("status") String status, @Param("empName") String empName);
    
    /**
     * 批量删除保养预约
     */
    void deleteBatch(@Param("ids") List<Long> ids);
    
    /**
     * 查询所有保养预约（用于导出等）
     */
    List<MaintenanceAppointment> listAll(@Param("param") MaintenanceAppointmentQueryParam param);
    
    /**
     * 添加保养预约
     */
    void add(MaintenanceAppointment appointment);
    
    /**
     * 根据用户ID查询保养预约
     */
    List<MaintenanceAppointment> listByUserId(@Param("userId") Long userId);
    
    /**
     * 根据用户ID统计保养预约数量
     */
    Integer countByUserId(@Param("userId") Long userId);
    
    /**
     * 根据员工名称查询保养预约
     */
    List<MaintenanceAppointment> listByEmpName(@Param("empName") String empName);
    
    /**
     * 获取空闲保养员列表
     * 查询job_id=3且status='空闲'的员工
     */
    @MapKey("id")
    List<Map<String, Object>> getMaintenanceStaff();
    
    /**
     * 统计当前员工关联的状态为'已确认'的保养预约数量
     */
    @Select("SELECT COUNT(*) FROM maintenance_appointments WHERE emp_name = #{empName} AND status = '已确认'")
    Integer countConfirmedByEmpName(@Param("empName") String empName);
    
    /**
     * 统计当前员工关联的状态为'已完成'的保养预约数量
     */
    @Select("SELECT COUNT(*) FROM maintenance_appointments WHERE emp_name = #{empName} AND status = '已完成'")
    Integer countCompletedByEmpName(@Param("empName") String empName);
    


}